import React, { Component } from 'react';
import css from './index.less';
import FilterSearch from '@/components/FilterSearch';
import TableList from '@/components/TableList';
import EditModal from '@/components/EditModal';
import { Button, Divider } from 'antd';
import { connect } from 'dva';
import AuthButton from '@/components/AuthButton';

type State = {
  selectProject: any;
};
type Props = {
  dispatch: Function;
};
class Department extends Component<Props> {
  state: State = {
    selectProject: {},
  };
  table = null;
  goEdit = data => {
    const url = `messageManage/notice/edit?id=${data.uuid || ''}&type=1`;
    this.props.dispatch({
      type: '$router/forward',
      payload: {
        url,
      },
    });
  };

  rowSelection = {
    onChange: (selectedRowKeys, selectedRows) => {
      this.setState({
        selectProject: selectedRows[0],
      });
      console.log(
        `selectedRowKeys: ${selectedRowKeys}`,
        'selectedRows: ',
        selectedRows,
      );
    },
    getCheckboxProps: (record: any) => ({
      disabled: record.name === 'Disabled User', // Column configuration not to be checked
      name: record.name,
    }),
  };
  /**
   * 除岗位
   * @param data
   */
  delete(data) {
    this.props.dispatch({
      type: 'base/delete',
      payload: {
        url: '/api/project/v1/delStoreProject',
        data: data,
      },
    });
  }
  filters = [
    {
      key: 'year',
      type: 'select',
      label: '选择年份',
    },
    {
      key: 'title',
      type: 'input',
      label: '标题',
      placeholder: '请输入姓名',
    },
  ];
  goDetail = ({ uuid }) => {
    const url = `messageManage/legislation/detail?id=${uuid || ''}&type=1`;
    this.props.dispatch({
      type: '$router/forward',
      payload: {
        url,
      },
    });
  };
  columns = [
    {
      title: '发布日期',
      dataIndex: 'createTime',
      format: 'YYYY-MM-DD',
      width: 150,
    },
    {
      title: '标题',
      dataIndex: 'title',
      render: (text, data) => (
        <Button type="link" onClick={() => this.goDetail(data)}>
          {text}
        </Button>
      ),
    },
    { title: '来源', dataIndex: 'from', width: 200 },
    {
      title: '操作',
      width: 325,
      render: (text, data) => (
        <span key={text}>
          <AuthButton onClick={() => this.goEdit(data)} role="edit_law">
            编辑
          </AuthButton>
          <Divider type="vertical" />
          <AuthButton onClick={() => this.delete(data)} role="del_law">
            删除
          </AuthButton>
        </span>
      ),
    },
  ];
  render() {
    const { selectProject } = this.state;
    return (
      <div>
        <FilterSearch
          filters={this.filters}
          onSearch={val => this.table.fetch(val)}
        >
          <AuthButton onClick={this.goEdit} type="primary" role="edit_law">
            添加
          </AuthButton>
          {/* <Button
            onClick={() => this.transferProject(5)}
            disabled={!selectProject}
          >
            导入
          </Button>
          <Button
            onClick={() => this.transferProject(1)}
            disabled={!selectProject}
          >
            导出
          </Button> */}
        </FilterSearch>
        <TableList
          tableProps={{
            rowSelection: {
              type: 'radio',
              ...this.rowSelection,
            },
          }}
          post
          rowKey="id"
          onRef={c => {
            this.table = c;
          }}
          columns={this.columns}
          source="/api/article/v1/law/query"
        />
      </div>
    );
  }
}

export default connect(state => state.base)(Department);
